using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

namespace DTO
{
    /// <summary> 
    ///Author: nnamthach@gmail.com 
    /// <summary>

    public class NewsInfo
    {
        #region Local Variable
        public enum Field
        {
            ID,
            IDNewsCategory,
            CreateDay,
            Title,
            Image,
            ShortDecribes,
            ShortDecribesVN,
            LongDecribes,
            LongDecribesVN,
            Source,
            CountPreview,
            IDStatus,
            TitleVN,
            Rank
        }
        private Int64 _ID;
        private Int32 _IDNewsCategory;
        private DateTime _CreateDay;
        private String _Title;
        private String _Image;
        private String _ShortDecribes;
        private String _ShortDecribesVN;
        private String _LongDecribes;
        private String _LongDecribesVN;
        private String _Source;
        private Int64 _CountPreview;
        private Int32 _IDStatus;
        private String _TitleVN;
        private Int32 _Rank;

        public Int64 ID { get { return _ID; } set { _ID = value; } }
        public Int32 IDNewsCategory { get { return _IDNewsCategory; } set { _IDNewsCategory = value; } }
        public DateTime CreateDay { get { return _CreateDay; } set { _CreateDay = value; } }
        public String Title { get { return _Title; } set { _Title = value; } }
        public String Image { get { return _Image; } set { _Image = value; } }
        public String ShortDecribes { get { return _ShortDecribes; } set { _ShortDecribes = value; } }
        public String ShortDecribesVN { get { return _ShortDecribesVN; } set { _ShortDecribesVN = value; } }
        public String LongDecribes { get { return _LongDecribes; } set { _LongDecribes = value; } }
        public String LongDecribesVN { get { return _LongDecribesVN; } set { _LongDecribesVN = value; } }
        public String Source { get { return _Source; } set { _Source = value; } }
        public Int64 CountPreview { get { return _CountPreview; } set { _CountPreview = value; } }
        public Int32 IDStatus { get { return _IDStatus; } set { _IDStatus = value; } }
        public String TitleVN { get { return _TitleVN; } set { _TitleVN = value; } }
        public Int32 Rank { get { return _Rank; } set { _Rank = value; } }

        #endregion LocalVariable

        #region Constructor
        public NewsInfo()
        {
            _ID = -1;
            _IDNewsCategory = 0;
            _CreateDay = DateTime.Now;
            _Title = "";
            _Image = "";
            _ShortDecribes = "";
            _ShortDecribesVN = "";
            _LongDecribes = "";
            _LongDecribesVN = "";
            _Source = "";
            _CountPreview = 0;
            _IDStatus = 0;
            _TitleVN = "";
            _Rank = 0;
        }
        public NewsInfo(
        Int64 ID,
        Int32 IDNewsCategory,
        DateTime CreateDay,
        String Title,
        String Image,
        String ShortDecribes,
        String ShortDecribesVN,
        String LongDecribes,
        String LongDecribesVN,
        String Source,
        Int64 CountPreview,
        Int32 IDStatus,
        String TitleVN,
        Int32 Rank
        )
        {
            _ID = ID;
            _IDNewsCategory = IDNewsCategory;
            _CreateDay = CreateDay;
            _Title = Title;
            _Image = Image;
            _ShortDecribes = ShortDecribes;
            _ShortDecribesVN = ShortDecribesVN;
            _LongDecribes = LongDecribes;
            _LongDecribesVN = LongDecribesVN;
            _Source = Source;
            _CountPreview = CountPreview;
            _IDStatus = IDStatus;
            _TitleVN = TitleVN;
            _Rank = Rank;
        }
        public NewsInfo(DataRow dr)
        {
            if (dr != null)
            {
                _ID = dr[Field.ID.ToString()] == DBNull.Value ? 0 : Convert.ToInt64(dr[Field.ID.ToString()]);
                _IDNewsCategory = dr[Field.IDNewsCategory.ToString()] == DBNull.Value ? 0 : Convert.ToInt32(dr[Field.IDNewsCategory.ToString()]);
                _CreateDay = dr[Field.CreateDay.ToString()] == DBNull.Value ? DateTime.Now : Convert.ToDateTime(dr[Field.CreateDay.ToString()]);
                _Title = dr[Field.Title.ToString()] == DBNull.Value ? "" : Convert.ToString(dr[Field.Title.ToString()]);
                _Image = dr[Field.Image.ToString()] == DBNull.Value ? "" : Convert.ToString(dr[Field.Image.ToString()]);
                _ShortDecribes = dr[Field.ShortDecribes.ToString()] == DBNull.Value ? "" : Convert.ToString(dr[Field.ShortDecribes.ToString()]);
                _ShortDecribesVN = dr[Field.ShortDecribesVN.ToString()] == DBNull.Value ? "" : Convert.ToString(dr[Field.ShortDecribesVN.ToString()]);
                _LongDecribes = dr[Field.LongDecribes.ToString()] == DBNull.Value ? "" : Convert.ToString(dr[Field.LongDecribes.ToString()]);
                _LongDecribesVN = dr[Field.LongDecribesVN.ToString()] == DBNull.Value ? "" : Convert.ToString(dr[Field.LongDecribesVN.ToString()]);
                _Source = dr[Field.Source.ToString()] == DBNull.Value ? "" : Convert.ToString(dr[Field.Source.ToString()]);
                _CountPreview = dr[Field.CountPreview.ToString()] == DBNull.Value ? 0 : Convert.ToInt64(dr[Field.CountPreview.ToString()]);
                _IDStatus = dr[Field.IDStatus.ToString()] == DBNull.Value ? 0 : Convert.ToInt32(dr[Field.IDStatus.ToString()]);
                _TitleVN = dr[Field.TitleVN.ToString()] == DBNull.Value ? "" : Convert.ToString(dr[Field.TitleVN.ToString()]);
                _Rank = dr[Field.Rank.ToString()] == DBNull.Value ? 0 : Convert.ToInt32(dr[Field.Rank.ToString()]);
            }
        }
        public NewsInfo(NewsInfo objEntr)
        {
            _ID = objEntr.ID;
            _IDNewsCategory = objEntr.IDNewsCategory;
            _CreateDay = objEntr.CreateDay;
            _Title = objEntr.Title;
            _Image = objEntr.Image;
            _ShortDecribes = objEntr.ShortDecribes;
            _ShortDecribesVN = objEntr.ShortDecribesVN;
            _LongDecribes = objEntr.LongDecribes;
            _LongDecribesVN = objEntr.LongDecribesVN;
            _Source = objEntr.Source;
            _CountPreview = objEntr.CountPreview;
            _IDStatus = objEntr.IDStatus;
            _TitleVN = objEntr.TitleVN;
            _Rank = objEntr.Rank;
        }
        #endregion Constructor

        #region InitTable
        public DataTable ToDataTable()
        {
            DataTable dt = new DataTable("News");
            dt.Columns.AddRange(new DataColumn[] { 
				new DataColumn(Field.ID.ToString(), typeof(Int64)),
				new DataColumn(Field.IDNewsCategory.ToString(), typeof(Int32)),
				new DataColumn(Field.CreateDay.ToString(), typeof(DateTime)),
				new DataColumn(Field.Title.ToString(), typeof(String)),
				new DataColumn(Field.Image.ToString(), typeof(String)),
				new DataColumn(Field.ShortDecribes.ToString(), typeof(String)),
				new DataColumn(Field.ShortDecribesVN.ToString(), typeof(String)),
				new DataColumn(Field.LongDecribes.ToString(), typeof(String)),
				new DataColumn(Field.LongDecribesVN.ToString(), typeof(String)),
				new DataColumn(Field.Source.ToString(), typeof(String)),
				new DataColumn(Field.CountPreview.ToString(), typeof(Int64)),
				new DataColumn(Field.IDStatus.ToString(), typeof(Int32)),
				new DataColumn(Field.TitleVN.ToString(), typeof(String)),
				new DataColumn(Field.Rank.ToString(), typeof(Int32))
			});
            return dt;
        }
        public DataRow ToDataRow(DataTable dt)
        {
            DataRow row = dt.NewRow();
            row[Field.ID.ToString()] = _ID;
            row[Field.IDNewsCategory.ToString()] = _IDNewsCategory;
            row[Field.CreateDay.ToString()] = _CreateDay;
            row[Field.Title.ToString()] = _Title;
            row[Field.Image.ToString()] = _Image;
            row[Field.ShortDecribes.ToString()] = _ShortDecribes;
            row[Field.ShortDecribesVN.ToString()] = _ShortDecribesVN;
            row[Field.LongDecribes.ToString()] = _LongDecribes;
            row[Field.LongDecribesVN.ToString()] = _LongDecribesVN;
            row[Field.Source.ToString()] = _Source;
            row[Field.CountPreview.ToString()] = _CountPreview;
            row[Field.IDStatus.ToString()] = _IDStatus;
            row[Field.TitleVN.ToString()] = _TitleVN;
            row[Field.Rank.ToString()] = _Rank;
            return row;
        }
        #endregion InitTable
    }
}
